package com.kl.modular.system.service.impl;

import com.kl.common.exception.SystemException;
import com.kl.modular.base.service.impl.BaseServiceImpl;
import com.kl.modular.system.dao.mapper.ArticleTypeMapper;
import com.kl.modular.system.dao.model.ArticleType;
import com.kl.modular.system.service.api.IArticleTypeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;


/**
 * 文章类型serviceImpl业务实现
 * @author xr_Yifan
 * @date 2017-12-12 08:52
 * @(C) xinrui Copyright 
 */
@Service
public class ArticleTypeServiceImpl extends BaseServiceImpl<ArticleTypeMapper, ArticleType> implements IArticleTypeService {

    private static final Logger logger = LoggerFactory.getLogger(ArticleTypeServiceImpl.class);

    public void deleteByArticleTypeId(String id) throws Exception {

        ArticleType articleType = new ArticleType();
        articleType.setParentId(Long.parseLong(id));
        int parentCounts = selectCountByEntity(articleType);
        if(parentCounts > 0){
            logger.error("删除文章类别发生错误>>该文章类别下级有数据，暂不能删除");
            throw new SystemException("该文章类别下级有数据，暂不能删除");
        }

        logicalDelete(id);

    }
}
